package com.heima.wemedia.scan.listener;


import com.heima.common.constants.KafkaMessageConstant;
import com.heima.wemedia.scan.service.WmNewsAutoscanService;
import io.micrometer.core.instrument.util.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.logging.log4j.core.appender.mom.kafka.KafkaManager;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.support.converter.KafkaMessageHeaders;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
@Slf4j
public class KafkaNewScanListener {
    @Resource
    private WmNewsAutoscanService wmNewsAutoScanService;

    @KafkaListener(topics = KafkaMessageConstant.WM_NEWS_AUTO_SCAN_TOPIC, groupId = "WM_NEWS_AUTO_SCAN")
    public void wmNewsAutoScan(ConsumerRecord<String, String> record) {
        String value = record.value();
        log.info("接收到消息 , 消息内容:{}", record.value());
        if (StringUtils.isNotBlank(value)) {
            log.info("开始进行文章自动审核 , 文章ID:{}", value);
            wmNewsAutoScanService.autoScanNews(Long.valueOf(value));
            log.info("文章自动审核完成 , 文章ID:{}", value);
        }
    }

}
